import { SendLoginWithRes } from "mvx-foundation";
export const waitingRegistry = new Map();
export function RegisterAutoLogin(net, uri, requestF, resType, resParser, loginFail, ...options) {
    waitingRegistry.set(net.getBaseUrl(), []);
    net.set401Delegate(async (net) => {
        let [_, err] = await SendLoginWithRes(uri, await requestF(), resType, net, resParser, ...options);
        let waiting = waitingRegistry.get(net.getBaseUrl());
        for (let w of waiting) {
            w(err);
        }
        waitingRegistry.set(net.getBaseUrl(), []);
        if (err) {
            await loginFail(err);
        }
    });
}
export function UnRegisterAutoLogin(net, net401delegate) {
    net.set401Delegate(net401delegate);
    waitingRegistry.delete(net.getBaseUrl());
}
